package com.jerry.wschat.model.vo;

import lombok.Data;

import java.io.Serializable;

/**
 * @author Jerry.Wu
 * @description:
 * @date 2018/9/12 14:14
 */
@Data
public class ReturnVO<T> implements Serializable {

    public static final int CODE_SUCCESS = 0;

    public static final int CODE_ERROR = 1;

    private T data;

    private String msg;

    private int code;

    public ReturnVO () {

    }

    public ReturnVO (T data, int code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

    public ReturnVO (T data, int code) {
        this.data = data;
        this.code = code;
    }

    public static<T> ReturnVO OK () {
        return ReturnVO.OK(null);
    }

    public static<T> ReturnVO OK (T data) {
        return ReturnVO.OK(data, null);
    }

    public static<T> ReturnVO OK (T data, String msg) {
        return new ReturnVO(data, CODE_SUCCESS, msg);
    }

    public static<T> ReturnVO ERROR () {
        return ReturnVO.ERROR(null);
    }

    public static<T> ReturnVO ERROR (String msg) {
        return ReturnVO.ERROR(null, msg);
    }

    public static<T> ReturnVO ERROR (T data, String msg) {
        return new ReturnVO(data, CODE_ERROR, msg);
    }

}
